package com.ostrich.cloud.ostrichBusinessWeb.app.Api;

import cn.hutool.core.bean.BeanUtil;
import com.ostrich.cloud.common.result.PageResult;
import com.ostrich.cloud.common.result.Result;
import com.ostrich.cloud.ostrichBusinessWeb.client.GoodsWebClient;
import com.ostrich.cloud.ostrichBusinessWeb.client.param.*;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.GoodsDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.TypeDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.param.*;
import com.ostrich.cloud.ostrichGoodsService.client.GoodsClient;
import com.ostrich.cloud.ostrichGoodsService.client.TypeClient;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import javax.annotation.Resource;
import javax.validation.Valid;
@RestController
public class GoodsWebApiImp implements GoodsWebClient {
    @Resource
    private GoodsClient goodsClient;

    @Resource
    private TypeClient typeClient;


    @Override
    public Result createGoods(CreateGoodsParam param) {
        boolean goods = goodsClient.createGoods(param);
        return Result.ok();
    }

    @Override
    public Result putGoods(ManagerGoodsParam param) {
        PutGoodsParam putGoodsParam = BeanUtil.copyProperties(param, PutGoodsParam.class);
        boolean b = goodsClient.putGoods(putGoodsParam);
        return Result.ok();
    }

    @Override
    public Result delGoods(Integer goodsId) {
        boolean b = goodsClient.delGoods(goodsId);
        return Result.ok();
    }

    @Override
    public GoodsDto getGoodsDto(Integer goodsId) {

        GoodsDto goodsDto = goodsClient.getGoodsDto(goodsId);
        return goodsDto;
    }

    @Override
    public PageResult<GoodsDto> getAllGoods(GetGoodsByBusinessParam getGoodsByBusinessParam) {
        GetGoodsParam param=BeanUtil.copyProperties(getGoodsByBusinessParam,GetGoodsParam.class);

        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);

        return goodsByCriteria;
    }

    @Override
    public PageResult<GoodsDto> typeSelectGoods(GetGoodsByTypeIdParam getGoodsByTypeIdParam) {

        GetGoodsParam param=BeanUtil.copyProperties(getGoodsByTypeIdParam,GetGoodsParam.class);

        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);

        return goodsByCriteria;
    }

    @Override
    public PageResult<GoodsDto> statusSelectGoods(GetGoodsByStatusParam getGoodsByStatusParam) {

        GetGoodsParam param=BeanUtil.copyProperties(getGoodsByStatusParam,GetGoodsParam.class);
        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);
        return goodsByCriteria;
    }

    @Override
    public PageResult<GoodsDto> linkeNameGoods(GetGoodsLikeNameParam getGoodsLikeNameParam) {
        GetGoodsParam param=BeanUtil.copyProperties(getGoodsLikeNameParam,GetGoodsParam.class);
        PageResult<GoodsDto> goodsByCriteria = goodsClient.getGoodsByCriteria(param);
        return goodsByCriteria;
    }

    @Override
    public Result takeDownGoods(@Valid TakeDownGoodsParam param) {
        PutGoodsParam param1=BeanUtil.copyProperties(param,PutGoodsParam.class);
        boolean b = goodsClient.putGoods(param1);
        return b?Result.ok():Result.error();
    }

    @Override
    public Result addType( AddTypeParam param) {
        typeClient.createType(param);
        return Result.ok();
    }

    @Override
    public Result delType(Integer typeId) {
        Boolean aBoolean = typeClient.delType(typeId);
        return aBoolean?Result.ok():Result.error();
    }

    @Override
    public Result putType(@Valid PutTypeParam putTypeParam) {

        Boolean aBoolean = typeClient.updateType(putTypeParam);
        return aBoolean?Result.ok():Result.error();
    }

    @Override
    public Result likeNameType(GetTypeLikeNameParam getTypeLikeNameParam) {

        SelectTypeParam param=BeanUtil.copyProperties(getTypeLikeNameParam,SelectTypeParam.class);

        PageResult<TypeDto> allTypeDto = typeClient.getAllTypeDto(param);

        return allTypeDto;
    }

    @Override
    public Result typeParentIdGetType(GetTypeByParentIdParam getTypeByParentIdParam) {
        if(getTypeByParentIdParam.getTypeParentId()==null){
            getTypeByParentIdParam.setTypeParentId(0);
        }
        SelectTypeParam param=BeanUtil.copyProperties(getTypeByParentIdParam,SelectTypeParam.class);
        PageResult<TypeDto> allTypeDto = typeClient.getAllTypeDto(param);
        return allTypeDto;
    }


}
